<template>
	<view>
	<u-navbar back-text="学号查找" :customBack="back" backIconColor="#fff" :backTextStyle="{'color':'#fff'}" :background="background"></u-navbar>
	<view class="content" v-if="logined">
		<view class="title">欢迎登录重庆大学新生报到系统</view>
		<u-form-item left-icon="account" label-width="120" prop="name">
			<u-input type="text" class="u-border-bottom u-m-b-20" v-model="user2.name" placeholder="请输入学生姓名" />
		</u-form-item>
		<u-form-item left-icon="lock" label-width="120" prop="idNumber">
			<u-input type="text" class="u-border-bottom" v-model="user2.idNumber" placeholder="请输入学生身份证号" />
		</u-form-item>
		<view class="u-demo-area">
					<u-button @click="twist()">学号查找</u-button>
		<u-form>
		<u-form-item >
					
		</u-form-item>
		</u-form>
		</view>
		<view @tap="toHome()" class="to-home">
		返回首页
		</view>
	</view>
	
	<view v-else>
		<view class="u-font-18 u-p-b-20">你的学号为：{{user2.stuNumber}}</view>
		<view class="u-font-18 u-p-b-20">你的密码为：{{user2.pwd}}</view>
		<view @tap="toHome()" class="to-home">
		返回首页	
		</view>
	</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				logined:true,
				background: {
					'background-image': 'linear-gradient(45deg, #2BC3C8, #84E7B9)'
				},
				user2:{
					name:"",
					idNumber:"",
					stuNumber:"",
					pwd:""
				}
			}
		},
		onLoad() {
			
		},
		computed: {
			inputStyle() {
				let style = {};
				if(this.mobile) {
					style.color = "#fff";
					style.backgroundColor = '#2BC3C8';
				}
				return style;
			}
		},
		methods:{
			toHome(){
				uni.switchTab({
					url: "/pages/mine/index"
				})
			},
			twist(){
				if (this.user2.name=="") {
					console.log("sjdhdh")
					uni.showToast({
						title: '请先输入学生姓名',
						icon: 'none'
					});
					return;
				}
				if (this.user2.idNumber=="") {
					uni.showToast({
						title: '请输入身份证号',
						icon: 'none'
					});
					return;
				}
				uni.request({
				 	url:"http://192.168.137.139:8080/queryStuNumber",
					method:"POST",
					data:this.user2,
					success: (res) => {
					 if (res.data.code*1==200) {
						 try{
							 uni.setStorageSync('user2',res.data.result)
							 this.user2=res.data.result
							this.logined=false
							console.log("页面跳转")
						 }catch(e){
							this.$u.toast('身份信息格式异常')
						 }
					 } else{
						this.$u.toast('用户名或者密码错误')
						console.log(res)
					 }
					}
				})
			},
			back(){
				this.$common.switchTabTo('/pages/index/index');
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		margin: 80rpx 60rpx 30rpx 60rpx;
	
		.title {
			text-align: center;
			font-size: 60rpx;
			font-weight: 500;
			margin-bottom: 100rpx;
		}
	
		.getCaptcha {
			background-color: #A9FFDA;
			color: #FFFFFF;
			border: none;
			font-size: 30rpx;
			margin: 60rpx 0;
			
			&::after {
				border: none;
			}
		}
		.alternative {
			color: $u-tips-color;
			display: flex;
			justify-content: space-between;
			margin-top: 30rpx;
		}
	}
	.buttom {
		.loginType {
			display: flex;
			padding: 200rpx 150rpx 150rpx 150rpx;
			justify-content:space-between;
			
			.item {
				display: flex;
				flex-direction: column;
				align-items: center;
				color: $u-content-color;
				font-size: 28rpx;
			}
		}
		
		.hint {
			padding: 20rpx 40rpx;
			font-size: 20rpx;
			color: $u-tips-color;
			text-align: center;
			.link {
				color: $u-type-warning;
			}
		}
	}
</style>

